import 'dart:ui';

import '../res/string.dart';
import 'package:get/get.dart';
import 'sp_util.dart';

class LocaleOptions {
  static updateLocale(Language language) {
    Locale? locale;
    if(language.language.isEmpty || language.country.isEmpty){
      locale = Get.deviceLocale;
    }else{
      locale = Locale(language.language,language.country);
    }
    if(locale != null){
      Get.updateLocale(locale);
    }
  }

  static Locale? getDefult(){
    Language? language = SPUtil.getLanguage();
    if (language == null){
      return Get.deviceLocale;
    }else{
      return Locale(language.language,language.country);
    }

  }


}

class Language {
  String name = '';
  String language = '';
  String country = '';
  bool isSelect = false;

  Language(this.name, this.language, this.country, {this.isSelect = false});

  Language.fromJson(Map<String, dynamic> json)
      : name = json['name'],
        language = json['language'],
        country = json['country'],
        isSelect = json['isSelect'];

  Map<String, dynamic> toJson() => {
        'name': name,
        'language': language,
        'country': country,
        'isSelect': isSelect,
      };

  bool isEmpty(){
    return language.isEmpty || country.isEmpty;
  }
}

///新增语言要在此处手动增加
final languageList = [
  Language(Str.settingLanguageDefault.tr, '', ''),
  Language('简体中文', 'zh', 'CN'),
  Language('繁體中文(香港)', 'zh', 'HK'),
  Language('繁體中文(台灣)', 'zh', 'TW'),
  Language('English', 'zh', 'US'),
];
